<?php

function smarty_function_html_cabinetselect($params, &$smarty) {

        require_once $smarty->_get_plugin_filepath('shared','escape_special_chars');

        $name = null;
    //$values = null;
    $options = null;
    $selected = array();
   // $output = null;
    $first = null;
    $field = 'l_name';
    $key = 'id';

    $extra = '';

        foreach($params as $_key => $_val) {
                switch($_key) {

                        case 'key':
                        $$_key = (string)$_val;
                        break;

                        case 'field':
                        $$_key = (string)$_val;
                        break;

                        case 'extra':
                        $$_key = (string)$_val;
                        break;

                         case 'options':
                $$_key = (array)$_val;
                break;

                        case 'name':
                        $$_key = (string)$_val;
                        break;

                        case 'selected':
                        $$_key = (string)$_val;
                        break;

                        case 'field':
                        $$_key = (string)$_val;
                        break;

                        case 'first':
                        $$_key = (string)$_val;
                        break;

                        case 'onchange':
                        $$_key = (string)$_val;
                        break;

                        case 'id':
                        $$_key = (string)$_val;
                        break;
                }
        }

        if (!empty($key)) {

                if (!empty($name)) {
                        $option = '<select name="' . $name . '" ' . $extra . " id=\"".$id."\" onchange=\"".$onchange."\" " .'>';
                } else {
                        $option = '<select name="' . $key . '" ' . $extra . '>';
                }

                if (isset($first)) {
                        $option .= '<option value="0">' . $first . '</option>';
                }
                //print_r($options);
                if (!empty($options)) {
                        foreach ($options as $v) {
                                if (!empty($selected) && $selected===(string)$v[$key]) {
                                        $option .= '<option value="' . $v[$key] . '" selected>' . $v[$field] . '</option>';
                                } else {
                                        $option .= '<option value="' . $v[$key] . '">' . $v[$field] . '</option>';
                                }
                        }
                } else {
                        $option .= '<option value="0"></option>';
                }
                $option .= '</select>';
        }
        return $option;
}

?>